{include file='head'/}
<body class="pear-container">
<div class="layui-card">
    <form class="layui-form layuimini-form" action="javascript:;" method="post" onsubmit="return dosub(this)">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label required">配置名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" value="" lay-verify="required" autocomplete="off"
                           class="layui-input" lay-reqtext="配置名称不能为空">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">配置类型</label>
                <div class="layui-input-inline">
                    <select name="fieldtype" class="select" style="width:230px" lay-filter="fieldtype">
                        <option value="textarea" selected>文本类型</option>
                        <option value="image">图片上传</option>
                        <!--<option value="attachment">附件上传</option>-->
                        <option value="radio">radio选项卡</option>
                        <option value="select">option下拉框</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">配置值</label>
                <div class="layui-input-block">
                    <div class="upload_mode mode_textarea span_input" id="config_show">
                        <textarea name="value[textarea]" class="layui-textarea" placeholder="例如：214243830"></textarea>
                    </div>
                    <div class="huicmf-upload upload_mode mode_image" style="display:none">
                        <div class="layui-input-inline" style="width: 50%">
                            <input type="text" name="value[image]" value=""
                                   onmouseover="hui_img_preview('image-select-input',this.value)"
                                   onmouseout="layer.closeAll();" id="image-select-input" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-input-inline" style="width: 120px">
                            <a class="layui-btn"
                               data-open-pic="{:__url('index/file_list',['type'=>'one','select_id'=>'image-select-input'])}">
                                <i class="layui-icon">&#xe67c;</i>选择图片
                            </a>
                        </div>
                    </div>

                    <div class="upload_mode mode_radio" style="display:none">
                        <textarea name="setting[radio]" class="layui-textarea"
                                  placeholder="选项用“|”分开（选项值用“:”分开【可以为空】），如“男:1|女:2|人妖:3"></textarea>&nbsp;
                        <input type="text" name="value[radio]" class="layui-input"
                               placeholder="默认值用配置值填写（如果有: 请填写 : 后面的。如 1）">
                    </div>
                    <div class="upload_mode mode_select" style="display:none">
                        <textarea name="setting[select]" class="layui-textarea"
                                  placeholder="选项用“|”分开（选项值用“:”分开【可以为空】），如“男:1|女:2|人妖:3”"></textarea>&nbsp;
                        <input type="text" name="value[select]" class="layui-input" style="width:180px"
                               placeholder="默认值用配置值填写">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">简洁说明</label>
                <div class="layui-input-block">
                    <input type="text" id="title" name="title" autocomplete="off" class="layui-input"
                           placeholder="例如：这个是站点QQ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block" id="status">
                    <input type="radio" name="status" value="1" title="启用" checked>
                    <input type="radio" name="status" value="0" title="禁用">
                </div>
            </div>

        </div>
        <div class="bottom">
            <div class="button-container">
                <button class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
</div>
</div>
</form>

{include file='footer'/}
<script>
  layui.use(['layer', 'jquery', 'form', 'upload'], function () {
    var layer = layui.layer,
      $ = layui.jquery,
      form = layui.form,
      upload = layui.upload;
    form.on('select(fieldtype)', function (data) {
      $('.upload_mode').hide();
      $('.mode_' + data.value).show();
    });
    //保存
    window.dosub = function (obj) {
      var reg = /^[A-Za-z0-9_]+$/;
      if ($("input[name='name']").val() == '' || !reg.test($("input[name='name']").val())) {
        layer.msg('配置名称必须为英文拼音数字_！');
        return false;
      }
      $.ajax({
        type: 'POST',
        url: "{:__url('system/config/custom_config_add')}",
        data: $(obj).serialize(),
        dataType: "json",
        success: function (res) {
          if (res.code === 200) {
            layer.msg(res.msg, {icon: 1, time: 2000}, function () {
              window.location.reload();
            })
          } else {
            layer.msg(res.msg, {icon: 2, time: 2000})
          }
        }
      });
    }
  });
</script>
</body>
</html>
